/*
 * TableListController.java 1.00 2008. 01. 15
 * 
 * Copyright (c) 2010 doitframe team. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of doitframe
 * team. You shall not disclose such Confidential Information and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with doitframe team.
 */
package doit.gen.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import doit.framework.controller.BaseDWR;
import doit.gen.service.ColumnService;
import doit.gen.util.Generator;

/**
 * <pre>
 * system      : 공통
 * menu        : 공통
 * source      : TableListController.java
 * description : 테이블 리스트 조회
 * </pre>
 * 
 * @version <pre>
 * 
 * 1.0	2008. 01. 15  monolist  최초 작성
 * 1.1
 * </pre>
 */

@SuppressWarnings("unchecked")
public class ColumnDWR extends BaseDWR {
    @Autowired
    private ColumnService columnService;

    public ColumnService getColumnService() {
        return columnService;
    }

    public void setColumnService(ColumnService columnService) {
        this.columnService = columnService;
    }

    /**
     * 서버 소스 생성
     * 
     * @param input
     * @return
     * @throws Exception
     */
    public Object makeServerSource(Map input) throws Exception {
        String[] tableNames = ((String) input.get("tableName")).split(",");
        String[] classNames = ((String) input.get("className")).split(",");

        for (int i = 0; tableNames != null && i < tableNames.length; i++) {
            Map data = new HashMap();
            data.put("tableName", tableNames[i]);
            List list = columnService.getColumns(data);

            if (list.size() > 0) {
                if( classNames != null && classNames[i] != null && classNames[i].length() > 0)
                    new Generator().generateServerSource(input, classNames[i], list);
                else
                    new Generator().generateServerSource(input, tableNames[i], list);
            }
        }

        return new Boolean(true);
    }

    /**
     * 클라이언트 소스 생성
     * 
     * @param input
     * @return
     * @throws Exception
     */
    public Object makeClientSource(Map input) throws Exception {

        new Generator().generateClientSource(input);

        return new Boolean(true);
    }

    /**
     * 테이블 컬럼 조회
     * @param input
     * @return
     * @throws Exception
     */
    public List getColumn(Map input) throws Exception {
        return columnService.getColumns(input);
    }
}
